package com.huaruan.youdi.http.okhttp;

import android.content.Intent;
import android.os.Looper;
import android.util.Log;

import com.huaruan.youdi.base.BaseApplication;
import com.huaruan.youdi.utils.AppUtils;
import com.huaruan.youdi.views.activitys.LoginActivity;


/**
 * Created by yushilong on 2015/5/4.
 */
public abstract class HttpCallback {
    /**
     * UI主线程回调
     *
     * @param object
     */
    public void success(Object object){
        Log.e("OnSuccessAndFaultSub:", "" + object.toString());
    }

    /**
     * UI主线程回调
     *
     * @param status
     * @param errorMsg
     */
    public void failure(int status, String errorMsg) {
        if (status == 5002||status == 5003||status == 401) {
            Intent intent = new Intent(BaseApplication.getInstance().getContext(), LoginActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            BaseApplication.getInstance().getContext().startActivity(intent);
        }else if (status != 200 && Looper.myLooper() == Looper.getMainLooper()) {
            AppUtils.toastShort(BaseApplication.getInstance().getContext(), errorMsg);
        }
        Log.e("HTTPFault", errorMsg);
    }

    /**
     * 非UI主线程回调
     *
     * @param object
     */
    public void asyncSuccess(Object object) {
        Log.e("OnSuccessAndFaultSub:", "" + object.toString());
    }

    /**
     * 非UI主线程回调
     *
     * @param status
     * @param errorMsg
     */
    public void asyncFailure(int status, String errorMsg) {
        if (status == 5002||status == 5003||status == 401) {
            Intent intent = new Intent(BaseApplication.getInstance().getContext(), LoginActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            BaseApplication.getInstance().getContext().startActivity(intent);
        }else if (status != 200 && Looper.myLooper() == Looper.getMainLooper()) {
            AppUtils.toastShort(BaseApplication.getInstance().getContext(), errorMsg);
        }
        Log.e("HTTPFault", errorMsg);
    }
}
